﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using ScreenMonitor.ServerLib;
using ServerUI.Setting;

namespace ServerUI
{
    public partial class ServerStats : DockContent
    {
        public ServerStats()
        {
            InitializeComponent();
        }

        private void RefreshStat()
        {
            this.txtIpaddr.Text = ServerGlobalSettingIpPort.ServerIpAddr.ToString();
            this.txtIpPort.Text = ServerGlobalSettingIpPort.ServerTcpListenPort.ToString();
            switch (ServerMain.GetState())
            {
                case ServerState.Created:
                    this.txtStatu.Text = "未初始化";
                    return;
                case ServerState.Inited:
                    this.txtStatu.Text = "未启动";
                    break;
                case ServerState.Started:
                    this.txtStatu.Text = "已启动";
                    break;
                case ServerState.Stoped:
                    this.txtStatu.Text = "已停止";
                    break;
            }
            //this.txtConnectCount.Text = ServerObjects.TcpCenter.ConnectionManager.ClientList.Count.ToString();
            //this.txtInQueueC.Text = ServerObjects.TcpCenter.Reader.GetQueueCount().ToString();
            //this.txtOperated.Text = ServerObjects.TcpCenter.Operator.GetQueueCount().ToString();
            //this.txtOutQueueC.Text = ServerObjects.TcpCenter.Sender.GetQueueCount().ToString();
            //this.txtUnGroupC.Text = ServerObjects.TcpCenter.Reader.GetUnGroupPkgCount().ToString();
            //this.txtListenC.Text = ServerObjects.TcpCenter.Listener.GetConnectCount().ToString();
            //this.txtOperC.Text = ServerObjects.TcpCenter.Operator.GetQueueCount().ToString();
        }

        private void ServerStats_Load(object sender, EventArgs e)
        {
            this.nudRefreshRate.Value = ServerUIRateSetting.ServerStatsWndRefreshRate;
            timer1.Interval = (int)this.nudRefreshRate.Value;
            timer1.Start();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            RefreshStat();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            RefreshStat();
        }

        private void ServerStats_FormClosed(object sender, FormClosedEventArgs e)
        {
            timer1.Stop();
        }

        private void nudRefreshRate_ValueChanged(object sender, EventArgs e)
        {
            ServerUIRateSetting.ServerStatsWndRefreshRate = (int)nudRefreshRate.Value;
        }
    }
}
